#include <projectdefinitions.h>
//----------------------------------------------------------------------------------------  
// soft-UART library
// date: 5.April 2009
// by M. Ossmann, FH Aachen

// RS232 sends D0 first !
// 'A'=0x41 = 0b01000001   is transmitted as 0100000101 ( on 5V side )
// start-bit==low, stop-bit==high ( on 5V side )

//--------------------------------- HARDWARE DEFINITION MACROS ----------------------------
// Receive data
#define RX1_PIN  PINE   // port from which the RXdata is read (FH board: port PINB)
#define RX1_DDR  DDRE   // DDR of the port (FH board: port DDRB)
#define RX1_PORT PORTE  // out port for turn on of pullup-resistors (FH board: port PORTB)
#define RX1_BIT  5      // selects bit of the port to be the RXin-pin (FH board: pin 2)
#define RX1_DELAY1 5    // delay from start-detect to middle of first data-bit
#define RX1_DELAY2 4    // delay between Bits
#define RX1fifoSIZE 128	// this number must (!!) be a power of 2
#define RX1fifoMASK (RX1fifoSIZE-1)  // so that this number can be used to mask off the indexes

// Send data
#define  TX1_DDR   DDRE	// DDR of the port (FH board: port DDRB)
#define  TX1_PORT  PORTE// out port for turn on of pullup-resistors (FH board: port PORTB)
#define  TX1_BIT   4	// selects bit of the port to be the RXin-pin (FH board: pin 3)
#define  TX1_DELAY 4    // delay between Bits
#define  TX1fifoSIZE 8	// this number must (!!) be a power of 2
#define  TX1fifoMASK (TX1fifoSIZE-1) // so that this number can be used to mask off the indexes



//---------------------- FUNCTION DECLARATIONS ---------------------------------------------

void Timer0init();

void RX1init();
uint8_t RX1fifoEmpty();
uint8_t getRX1char();
uint8_t getRX1char_nw();
uint8_t  TX1fifo[TX1fifoSIZE] ;
volatile uint8_t TX1fifoPutIdx;
volatile uint8_t TX1fifoGetIdx;
uint8_t  TX1timer; 		// conts from 4 to 1 to get bit-Rate as UARTclk / 4
uint16_t TX1shiftReg; 	// character to be transmitted is put here together with start and stop-bit. Content then is shifted out LSB first
void TX1init();
void TX1char(uint8_t c);
void TX1string(const char *s );
void TX1string_p(const char *progmem_s);
